<html>
<head>
<meta charset="UTF-8">
<title>KBEngine - KBEngine base</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>KBEngine module</h1>
This <a href="KBEngine.html">KBEngine</a> module provides the Python script 
access to the <a href="../Classes/Entity.html">entity</a>'s base part, in particular 
it provides the registration and removal of timers, as well as the creation 
of <a href="../Classes/Entity.html">entities</a>.
<h2><a href="#" onClick="obj=document.getElementById( 'classes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Classes</a></h2>
<table id="classes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="class_list"><a href="../Classes/Entity.html" class="class_list" >Entity</a></span>
</td></tr>

<tr><td>
<span class="class_list"><a href="../Classes/Proxy.html" class="class_list" >Proxy</a></span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member functions</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#addWatcher" class="function_list" >addWatcher</a>( path, dataType, getFunction ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#address" class="function_list" >address</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#MemoryStream" class="function_list" >MemoryStream</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#charge" class="function_list" >charge</a>( ordersID, dbID, byteDatas, pycallback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntity" class="function_list" >createEntity</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityAnywhere" class="function_list" >createEntityAnywhere</a>( entityType, *params, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityRemotely" class="function_list" >createEntityRemotely</a>( entityType, baseMB, *params, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityFromDBID" class="function_list" >createEntityFromDBID</a>( entityType, dbID, callback, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityAnywhereFromDBID" class="function_list" >createEntityAnywhereFromDBID</a>( entityType, dbID, callback, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityRemotelyFromDBID" class="function_list" >createEntityRemotelyFromDBID</a>( entityType, dbID, baseMB, callback, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntityLocally" class="function_list" >createEntityLocally</a>( entityType, *params ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#debugTracing" class="function_list" >debugTracing</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#delWatcher" class="function_list" >delWatcher</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#deleteEntityByDBID" class="function_list" >deleteEntityByDBID</a>( entityType, dbID, callback, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#deregisterReadFileDescriptor" class="function_list" >deregisterReadFileDescriptor</a>( fileDescriptor ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#deregisterWriteFileDescriptor" class="function_list" >deregisterWriteFileDescriptor</a>( fileDescriptor ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#executeRawDatabaseCommand" class="function_list" >executeRawDatabaseCommand</a>( command, callback, threadID, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#genUUID64" class="function_list" >genUUID64</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getResFullPath" class="function_list" >getResFullPath</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcher" class="function_list" >getWatcher</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcherDir" class="function_list" >getWatcherDir</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getAppFlags" class="function_list" >getAppFlags</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#hasRes" class="function_list" >hasRes</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#isShuttingDown" class="function_list" >isShuttingDown</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#listPathRes" class="function_list" >listPathRes</a>( path, extension ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#lookUpEntityByDBID" class="function_list" >lookUpEntityByDBID</a>( entityType, dbID, callback, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#matchPath" class="function_list" >matchPath</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#open" class="function_list" >open</a>( res, mode, encoding ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#publish" class="function_list" >publish</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#quantumPassedPercent" class="function_list" >quantumPassedPercent</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#registerReadFileDescriptor" class="function_list" >registerReadFileDescriptor</a>( fileDescriptor, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#registerWriteFileDescriptor" class="function_list" >registerWriteFileDescriptor</a>( fileDescriptor, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#reloadScript" class="function_list" >reloadScript</a>( fullReload ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#scriptLogType" class="function_list" >scriptLogType</a>( logType ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#setAppFlags" class="function_list" >setAppFlags</a>( flags ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#time" class="function_list" >time</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#urlopen" class="function_list" >urlopen</a>( url, callback, postData, headers ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callback functions</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#onBaseAppReady" class="function_list" >onBaseAppReady</a>( isBootstrap ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onBaseAppShutDown" class="function_list" >onBaseAppShutDown</a>( state ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onCellAppDeath" class="function_list" >onCellAppDeath</a>( addr ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onFini" class="function_list" >onFini</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onBaseAppData" class="function_list" >onBaseAppData</a>( key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onBaseAppDataDel" class="function_list" >onBaseAppDataDel</a>( key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onGlobalData" class="function_list" >onGlobalData</a>( key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onGlobalDataDel" class="function_list" >onGlobalDataDel</a>( key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onInit" class="function_list" >onInit</a>( isReload ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLoseChargeCB" class="function_list" >onLoseChargeCB</a>( orderID, dbID, success, datas ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onReadyForLogin" class="function_list" >onReadyForLogin</a>( isBootstrap ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onReadyForShutDown" class="function_list" >onReadyForShutDown</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onAutoLoadEntityCreate" class="function_list" >onAutoLoadEntityCreate</a>( entityType, dbID ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'attributes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Attributes</a></h2>
<table id="attributes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><a href="#LOG_ON_ACCEPT" class="attribute_list" >LOG_ON_ACCEPT</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_ON_REJECT" class="attribute_list" >LOG_ON_REJECT</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_ON_WAIT_FOR_DESTROY" class="attribute_list" >LOG_ON_WAIT_FOR_DESTROY</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_DBG" class="attribute_list" >LOG_TYPE_DBG</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_ERR" class="attribute_list" >LOG_TYPE_ERR</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_INFO" class="attribute_list" >LOG_TYPE_INFO</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_NORMAL" class="attribute_list" >LOG_TYPE_NORMAL</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_WAR" class="attribute_list" >LOG_TYPE_WAR</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#NEXT_ONLY" class="attribute_list" >NEXT_ONLY</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#component" class="attribute_list" >component</a></td><td>&nbsp; Read-only <a href="STRING.html">string</a></td></tr>

<tr valign=top><td><a href="#entities" class="attribute_list" >entities</a></td><td>&nbsp; <a href="Entities.html">Entities</a>
</td></tr>

<tr valign=top><td><a href="#baseAppData" class="attribute_list" >baseAppData</a></td><td>&nbsp; <a href="baseAppData.html">GlobalDataClient</a>
</td></tr>

<tr valign=top><td><a href="#globalData" class="attribute_list" >globalData</a></td><td>&nbsp; <a href="baseAppData.html">GlobalDataClient</a></td></tr>

</table>

<hr>
<h2>Member functions documentation</h2>

<a name="addWatcher"></a><p class="function_definition">
<span class="function_definition">def addWatcher( <i>path, dataType, getFunction</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Interacts with the debug monitoring system, allowing the user to register 
a monitoring variable with the monitoring system.
<br><br>
Example:
<br>

<pre>
>>> def countPlayers( ):
>>>     i = 0
>>>     for e in KBEngine.entities.values():
>>>     	if e.__class__.__name__ == "Avatar":
>>>     		i += 1
>>>     return i
>>>
>>> <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#addWatcher>addWatcher</a>( "players", "UINT32", countPlayers )
</pre>
<br><br>
This function adds a watch variable under the "scripts/players" watch path. 
The function countPlayers is called when the watcher observes.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
Create a monitored path.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dataType</i></span></td><td><span class="function_parameter_description">
The value type of the monitor variable. Reference: <a href=../../basetypes.html>Basic data types</a>
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>getFunction</i></span></td><td><span class="function_parameter_description">
This function is called when the observer retrieves the variable. This 
function returns a value representing a watch variable without arguments.
</span></td></tr>

</table>
</p>



<a name="address"></a><p class="function_definition">
<span class="function_definition">def address( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns the address of the internal network interface.
</div>




<a name="MemoryStream"></a><p class="function_definition">
<span class="function_definition">def MemoryStream( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns a new MemoryStream object.<br>
<br>
The MemoryStreamobject stores binary information. This type is provided 
to allow the user to easily serialize and deserialize the Python base 
types following KBEngine underlying serialization rules.
<br><br>
For example, you can use this object to construct a network packet that 
KBEngine can parse.
<br><br>
Usage:
<pre>
>>> s = KBEngine.MemoryStream()
>>> s
>>> b''
>>> s.append("UINT32", 1)
>>> s.pop("UINT32")
>>> 1
</pre>
<br><br>
The types that MemoryStream currently supports are only basic data types. 
Reference: <a href=../../basetypes.html>Basic data types</a>
</div>



<a name="charge"></a><p class="function_definition">
<span class="function_definition">def charge( <i>ordersID, dbID, byteDatas, pycallback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Billing interface.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>ordersID</i></span></td><td><span class="function_parameter_description">
string, order ID.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
uint64, the <a href=../Classes/Entity.html#databaseID>databaseID</a> of 
the entity.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>byteDatas</i></span></td><td><span class="function_parameter_description">
bytes, with data, which is parsed and defined by the developer.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>pycallback</i></span></td><td><span class="function_parameter_description">
Billing callback.<br>
Billing callback prototype: (When calling KBEngine.chargeResponse in 
interfaces, the callback is called if an order is set to callback)<br>
&nbsp;def on*ChargeCB(self, orderID, dbID, success, datas):<br>
&nbsp;&nbsp;&nbsp;ordersID: string, OrderID<br>
&nbsp;&nbsp;&nbsp;dbID: uint64, usually the <a href=../Classes/Entity.html#databaseID>databaseID</a> of the entity.<br>
&nbsp;&nbsp;&nbsp;success: bool, whether the order succeeded
&nbsp;&nbsp;&nbsp;datas: bytes, with data, parsed and defined by the developer.<br>
</span></td></tr>

</table>
</p>

<a name="createEntity"></a><p class="function_definition">
<span class="function_definition">def createEntity( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntityLocally>createEntityLocally</a> 
alias.
</div>

<a name="createEntityAnywhere"></a><p class="function_definition">
<span class="function_definition">def createEntityAnywhere( <i>entityType, params, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Create a new base <a href="../Classes/Entity.html">Entity</a>. The server 
can choose any <a href="../index.html">Baseapp</a> to create an <a href="../Classes/Entity.html">Entity</a>.
<br><br>
This method should be preferred over <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntityLocally>createEntityLocally</a> 
so the server has the flexibility to choose a suitable <a href="../index.html">Baseapp</a> 
to create an entity.
<br><br>
The function parameters need to provide the type of entity created, and there is 
also a Python dictionary as a parameter to initialize the entities value.
<br><br>
The Python dictionary does not require the user to provide all of the 
properties, and the default values provided by the entity definition file 
".def" are defaults.
<br><br>
Example:<br>
<pre>
params = {
	"name" : "kbe", # base, BASE_AND_CLIENT
	"HP" : 100,	# cell, ALL_CLIENT, in cellData
	"tmp" : "tmp"	# baseEntity.tmp
}

def onCreateEntityCallback(entity)
	print(entity)

createEntityAnywhere("Avatar", params, onCreateEntityCallback)
</pre>

</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of <a href="../Classes/Entity.html">Entity</a> 
to create. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>params</i></span></td><td><span class="function_parameter_description">
optional parameter, a Python dictionary object. If a specified key is an 
<a href="../Classes/Entity.html">Entity</a> attribute, its value will be 
used to initialize the properties of this <a href="../Classes/Entity.html">Entity</a>.
If the key is a <a href="Cell.html">Cell</a> attribute, it will be added 
to the '<a href=../Classes/Entity.html#cellData>cellData</a>' attribute 
of the <a href="../Classes/Entity.html">Entity</a>. This <a href=../Classes/Entity.html#cellData>cellData</a>' 
attribute is a Python dictionary and will be used later to initialize the 
attributes of the cell entity.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback function that is called when the entity is created. 
The callback function takes one argument, when the <a href="../Classes/Entity.html">Entity</a>
is created successfully it is the entity's <a href=../../keywords.html#EntityCall>entityCall</a>, 
on failure it is None.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Returns the <a href=../../keywords.html#EntityCall>entityCall</a> of the 
<a href="../Classes/Entity.html">Entity</a> through the callback.
</td></tr>
</table>
</p>



<a name="createEntityRemotely"></a><p class="function_definition">
<span class="function_definition">def createEntityRemotely( <i>entityType, baseMB, params, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Create a new <a href="../Classes/Entity.html">Entity</a> on the specified 
baseapp through the baseMB parameter.
<br><br>
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntityLocally>createEntityAnywhere</a> 
should be preferred over this method to allow the server to decide which is the most suitable 
<a href="../index.html">Baseapp</a> to create the entity on for load balancing purposes.

<br><br>
The function parameters need to provide the type of the created entity, 
and there is also a Python dictionary as a parameter to initialize the 
entity's value.
<br><br>

This Python dictionary does not require the user to provide all of the 
properties, and the default values provided by the entity definition 
file  ". def" are defaults.
<br><br>
Example:<br>
<pre>
params = {
	"name" : "kbe", # base, BASE_AND_CLIENT
	"HP" : 100,	# cell, ALL_CLIENT, in cellData
	"tmp" : "tmp"	# baseEntity.tmp
}

def onCreateEntityCallback(entity)
	print(entity)

createEntityRemotely("Avatar", baseEntityCall, params, onCreateEntityCallback)
</pre>

</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of <a href="../Classes/Entity.html">Entity</a> 
to create. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>baseMB</i></span></td><td><span class="function_parameter_description">
BaseEntityCall which is a base <a href="../Classes/Entity.html">Entity</a> EntityCall.
The entity will be created on the baseapp process corresponding to this 
entity.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>params</i></span></td><td><span class="function_parameter_description">
Optional parameters, a Python dictionary object. If a specified key is an 
<a href="../Classes/Entity.html">Entity</a> attribute, its value will be 
used to initialize the properties of this <a href="../Classes/Entity.html">Entity</a>. 
If this key is a <a href="Cell.html">Cell</a> attribute, it will be added 
to the <a href="../Classes/Entity.html">Entity</a>'s '<a href=../Classes/Entity.html#cellData>cellData</a>' 
attribute. This '<a href=../Classes/Entity.html#cellData>cellData</a>' 
attribute is a Python dictionary and will be used later to initialize 
the attributes of the cell entity.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback function that is called when the entity is created. 
The callback takes one argument, on success it is an <a href="../Classes/Entity.html">Entity</a>ʵ���<a href=../../keywords.html#EntityCall>entityCall</a>, 
on failure it is None.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Returns the <a href="../Classes/Entity.html">Entity</a>'s  <a href=../../keywords.html#EntityCall>entityCall</a> 
through the callback.
</td></tr>
</table>
</p>



<a name="createEntityFromDBID"></a><p class="function_definition">
<span class="function_definition">def createEntityFromDBID( <i>entityType, dbID, callback, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Create an <a href="../Classes/Entity.html">Entity</a> by loading data 
from the database. The new <a href="../Classes/Entity.html">Entity</a> will 
be created on the <a href="../index.html">Baseapp</a> that called this function. 
If the <a href="../Classes/Entity.html">Entity</a> has been checked out 
from the database, a reference to this existing entity will be returned.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the <a href="../Classes/Entity.html">Entity</a> type to 
load. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
Specifies the database ID of the entity to create. The database ID of this 
entity is stored in the entity's <a href=../Classes/Entity.html#databaseID>databaseID</a> 
attribute.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback function that is called when the operation is complete. 
The callback function has three parameters: baseRef, databaseID, and wasActive. 
If the operation is successful, baseRef will be an <a href=../../keywords.html#EntityCall>entityCall</a> 
or a direct reference to the newly created <a href="../Classes/Entity.html">Entity</a>. 
The databaseID will be the database ID of the entity. wasActive will be 
True if baseRef is a reference to an already existing entity (checked out 
from the database). If the operation fails the three parameters will be 
baseRef - None, databaseID - 0, wasActive - False.
<br>
The most common reason for failure is that the entity does not exist in 
the database, but occasionally other errors such as timeouts or ID 
allocation failure.

</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specified by a database interface, and the 
"default" interface is used by default. Database interfaces are defined 
in kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>


<a name="createEntityAnywhereFromDBID"></a><p class="function_definition">
<span class="function_definition">def createEntityAnywhereFromDBID( <i>entityType, dbID, callback, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Create an <a href="../Classes/Entity.html">Entity</a> by loading data 
from the database. The server may choose any <a href="../index.html">Baseapp</a> 
to create the <a href="../Classes/Entity.html">Entity</a>.
<br><br>
Using this function will help BaseApps load balance.
<br><br>
If the entity has been checked out from the database, a reference to the 
existing <a href="../Classes/Entity.html">Entity</a> will be returned. 
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the <a href="../Classes/Entity.html">Entity</a> type to 
load. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
Specifies the database ID of the entity to create. The database ID of this 
entity is stored in the entity's <a href=../Classes/Entity.html#databaseID>databaseID</a> 
attribute.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback function that is called when the operation is complete. 
The callback function has three parameters: baseRef, databaseID, and wasActive. 
If the operation is successful, baseRef will be an <a href=../../keywords.html#EntityCall>entityCall</a> 
or a direct reference to the newly created <a href="../Classes/Entity.html">Entity</a>. 
The databaseID will be the database ID of the entity. wasActive will be 
True if baseRef is a reference to an already existing entity (checked out 
from the database). If the operation fails the three parameters will be 
baseRef - None, databaseID - 0, wasActive - False.
<br>
The most common reason for failure is that the entity does not exist in 
the database, but occasionally other errors such as timeouts or ID 
allocation failure.

</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specified by a database interface, and the 
"default" interface is used by default. Database interfaces are defined 
in kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The <a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a> 
through the callback.
</td></tr>
</table>
</p>


<a name="createEntityRemotelyFromDBID"></a><p class="function_definition">
<span class="function_definition">def createEntityRemotelyFromDBID( <i>entityType, dbID, baseMB, callback, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Load data from the database and create an <a href="../Classes/Entity.html">Entity</a> 
on the baseapp specified via the baseMB parameter.
<br><br>
If the entity has been checked out from the database, a reference to the 
existing <a href="../Classes/Entity.html">Entity</a> will be returned.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the <a href="../Classes/Entity.html">Entity</a> type to 
load. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
Specifies the database ID of the entity to create. The database ID of this 
entity is stored in the entity's <a href=../Classes/Entity.html#databaseID>databaseID</a> 
attribute.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback function that is called when the operation is complete. 
The callback function has three parameters: baseRef, databaseID, and wasActive. 
If the operation is successful, baseRef will be an <a href=../../keywords.html#EntityCall>entityCall</a> 
or a direct reference to the newly created <a href="../Classes/Entity.html">Entity</a>. 
The databaseID will be the database ID of the entity. wasActive will be 
True if baseRef is a reference to an already existing entity (checked out 
from the database). If the operation fails the three parameters will be 
baseRef - None, databaseID - 0, wasActive - False.
<br>
The most common reason for failure is that the entity does not exist in 
the database, but occasionally other errors such as timeouts or ID 
allocation failure.

</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specified by a database interface, and the 
"default" interface is used by default. Database interfaces are defined 
in kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Returns the <a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a> 
through the callback.
</td></tr>
</table>
</p>



<a name="createEntityLocally"></a><p class="function_definition">
<span class="function_definition">def createEntityLocally( <i>entityType, params</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Create a new <a href="../Classes/Entity.html">Entity</a>. 
The function parameters need to provide the type of the created entity, 
and there is also an optional Python dictionary as paramater to initialize 
the entity's values.
<br><br>
The Python dictionary does not require the user to provide all of the properties, and the default values provided by the entity definition file  ".def" are defaults.
<br><br>
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntityLocally>createEntityAnywhere</a> 
should be preferred over this method to allow the server to decide which is the most suitable 
<a href="../index.html">Baseapp</a> to create the entity on for load balancing purposes.
<br><br>
It should be noted that this method returns the entity instantly without 
a callback, and is also guaranteed to return a direct reference to the <a href=../Classes/Entity.html>Entity</a> object, 
rather than its <a href=../../keywords.html#EntityCall>EntityCall</a>. 
It is suitable to use this method over <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntityAnywhere>createEntityAnywhere</a> 
when you need to manage the entities life cycle (such as control when 
destroy is called on the entity) or access the entities attributes from 
the creating entity, because as described in the <a href=../../keywords.html#EntityCall>EntityCall</a> 
documentation, it is not possible to access attributes or call methods not 
listed in the entity's def file using the <a href=../../keywords.html#EntityCall>EntityCall</a>. 
This method is also necessary to use when you need a direct reference to an entity 
(as it's not possible to get one on a different baseapp). Many functions take 
an EntityCall as a parameter, but some require a direct reference to the 
entity (such as <a href=../Classes/Proxy.html>Proxy</a>.<a href=../Classes/Proxy.html#giveClientTo>giveClientTo</a>).
<br><br>
Example:<br>
<pre>
params = {
	"name" : "kbe", # base, BASE_AND_CLIENT
	"HP" : 100,	# cell, ALL_CLIENT, in cellData
	"tmp" : "tmp"	# baseEntity.tmp
}

baseEntity = createEntityLocally("Avatar", params)
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of entity to create. Valid entity types are 
listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>params</i></span></td><td><span class="function_parameter_description">
optional parameter, a Python dictionary object. If a specified key is an 
<a href="../Classes/Entity.html">Entity</a> attribute, its value will be 
used to initialize the properties of this <a href="../Classes/Entity.html">Entity</a>.
If the key is a <a href="Cell.html">Cell</a> attribute, it will be added 
to the '<a href=../Classes/Entity.html#cellData>cellData</a>' attribute 
of the <a href="../Classes/Entity.html">Entity</a>. This <a href=../Classes/Entity.html#cellData>cellData</a>' 
attribute is a Python dictionary and will be used later to initialize the 
attributes of the cell entity.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>The newly created <a href="../Classes/Entity.html">Entity</a>.
</td></tr>
</table>
</p>




<a name="debugTracing"></a><p class="function_definition">
<span class="function_definition">def debugTracing( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Outputs the Python extended object counter currently tracked by KBEngine.<br>
Extended objects include: fixed dictionary, fixed array, Entity, EntityCall...<br>
If the counter is not zero when the server is shut down normally, it means 
that the leak already exists and the log will output an error message.<br><br>
ERROR cellapp [0x0000cd64] [2014-11-12 00:38:07,300] - PyGC::debugTracing(): FixedArray : leaked(128)<br>
ERROR cellapp [0x0000cd64] [2014-11-12 00:38:07,300] - PyGC::debugTracing(): EntityCall : leaked(8)
</div>



<a name="delWatcher"></a><p class="function_definition">
<span class="function_definition">def delWatcher( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Interacts with the debug monitoring system, allowing users to delete 
monitored variables in the script.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
The path to the variable to delete.
</span></td></tr>

</table>
</p>


<a name="deleteEntityByDBID"></a><p class="function_definition">
<span class="function_definition">def deleteEntityByDBID( <i>entityType, dbID, callback, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Deletes the specified entity (including the child table data generated 
by the attribute) from the database. If the entity is not checked out 
from the database, the deletion is successful. If the entity has been 
checked out from the database, <a href="KBEngine.html">KBEngine</a> will fail to delete and return the 
<a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a> 
in the callback.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of Entity to delete. Valid entity types are 
listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
Specifies the database ID of the entity to delete. The database ID of the 
entity is stored in the entity's databaseID attribute.<a href=../Classes/Entity.html#databaseID>databaseID</a>���ԡ�
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
An optional callback, with only one parameter. When the entity has not 
been checked out from the database it will be deleted successfully and 
the parameter will be True. If the entity has been checked out from the 
database then the parameter is the <a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
String, optional parameter, specifies a database interface. By default it 
uses the "default" interface. Database interfaces are defined by kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>



<a name="deregisterReadFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def deregisterReadFileDescriptor( <i>fileDescriptor</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Unregisters the callback registered with <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#registerReadFileDescriptor>registerReadFileDescriptor</a>.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
socket descriptor/file descriptor
</span></td></tr>

</table>
</p>

<a name="deregisterWriteFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def deregisterWriteFileDescriptor( <i>fileDescriptor</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Unregisters the callback registered with <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#registerWriteFileDescriptor>registerWriteFileDescriptor</a>.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
socket descriptor/file descriptor.
</span></td></tr>

</table>
</p>



<a name="executeRawDatabaseCommand"></a><p class="function_definition">
<span class="function_definition">def executeRawDatabaseCommand( <i>command, callback, threadID, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function executes a database command on the database, which 
is directly parsed by the relevant database.
<br><br>
Please note that using this function to modify entity data may not be 
effective because if the entity has been checked out, the modified data 
will still be archived by the entity and cause overwriting.<br>
This function is strongly not recommended for reading or modifying entity data.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>command</i></span></td><td><span class="function_parameter_description">
This database command will be different for different database configuration 
scenarios. For a MySQL database it is an SQL query.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter, callback object (for example, a function) called 
back with the command execution result. <br>
This callback has 4 parameters: result set, number of rows affected, 
auto value, error message.<br>
Example:<br>
def sqlcallback(result, rows, insertid, error):
&nbsp;&nbsp;&nbsp;&nbsp;print(result, rows, insertid, error)
<br><br>

As the above example shows, the result parameter corresponds to the 
"result set", and the result set parameter is a row List. Each line is a 
list of strings containing field values. If the command execution does not 
return a result set (for example, a DELETE command), or the command 
execution encounters an error, the result set is None.
<br><br>

The rows parameter is the "number of rows affected", which is an integer 
indicating the number of rows affected by the command execution. This 
parameter is only relevant for commands that do not return results 
(such as DELETE).<br>
This parameter is None if there is a result set return or if there is an 
error in the command execution.
<br><br>

The insertid is a long value, similar to an entity's databaseID. When 
successfully inserting data int a table with an auto long type field, it 
returns the data at the time of insertion. <br>
More information can be found in mysql's mysql_insert_id() method. In 
addition, this parameter is only meaningful when the database type is 
mysql.
<br><br>

Error corresponds to the "error message", when the command execution 
encounters an error, this parameter is a string describing the error. 
This parameter is None when the command execution has not occurred.
</p></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>threadID</i></span></td><td><span class="function_parameter_description">
int32, optional parameter, specifies a thread to process this command. 
Users can use this parameter to control the execution order of certain 
commands (dbmgr is multi-threaded). The default is not specified. If threadId 
is the ID of an entity, it will be added to the entity's archive queue 
and written by the thread one by one.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specifies a database interface. By default it 
uses the "default" interface. Database interfaces are defined by kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>



<a name="genUUID64"></a><p class="function_definition">
<span class="function_definition">def genUUID64( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function generates a 64-bit unique ID.<br>
Note: This function depends on the baseapp server process startup parameter 
'gus'. Please set the startup parameters to be unique.<br>
In addition, if gus exceeds 65535, this function can only remain unique 
for the current process.
<br>
<br>
Usage:<br>
Unique IDs can be generated on multiple service processes and do not 
conflict.<br>
A room ID can be generated on multiple service processes and no 
uniqueness verification is required.<br>
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Returns a 64-bit integer.
</td></tr>
</table>
</p>


<a name="getResFullPath"></a><p class="function_definition">
<span class="function_definition">def getResFullPath( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the absolute path of a resource.
<br>Note: Resource must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, if there is an absolute path to the given resource, otherwise 
returns null.
</td></tr>
</table>
</p>


<a name="getWatcher"></a><p class="function_definition">
<span class="function_definition">def getWatcher( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Gets the value of a watch variable from the KBEngine debugging system.
<br>
<br>
Example: In the Python console of baseapp1: <br>
>>>KBEngine.getWatcher("/root/stats/runningTime")
<br>
12673648533
<br>
<br>
>>>KBEngine.getWatcher("/root/scripts/players")
<br>
32133
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path of the variable including the variable name 
(can be viewed on the GUIConsole watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The value of the variable.
</td></tr>
</table>
</p>


<a name="getWatcherDir"></a><p class="function_definition">
<span class="function_definition">def getWatcherDir( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get a list of elements (directories, variable names) under the watch 
directory from the KBEngine debugging system.
<br>
<br>
Example: In the Python console of baseapp1 enter:<br>
>>>KBEngine.getWatcher("/root")
<br>
('stats', 'objectPools', 'network', 'syspaths', 'ThreadPool', 'cprofiles', 'scripts', 'numProxices', 'componentID', 'componentType', 'uid', 'numClients', 'globalOrder', 'username', 'load', 'gametime', 'entitiesSize', 'groupOrder')
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path to this variable (can be viewd on the GUIConsole 
watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Monitors the list of elements in the directory (directory, variable name).
</td></tr>
</table>
</p>



<a name="getAppFlags"></a><p class="function_definition">
<span class="function_definition">def getAppFlags( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the flags of the current engine APP, Reference: <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#setAppFlags>setAppFlags</a>.
<br>
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
KBEngine.APP_FLAGS_*
</td></tr>
</table>
</p>



<a name="hasRes"></a><p class="function_definition">
<span class="function_definition">def hasRes( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Use this interface to determine if a relative path exists.<br>
Note: Resource must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Example:
<br>
<br>
>>>KBEngine.hasRes("scripts/entities.xml")
<br>
True
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
bool, True if relative path exists, otherwise False.
</td></tr>
</table>
</p>





<a name="isShuttingDown"></a><p class="function_definition">
<span class="function_definition">def isShuttingDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns whether the server is shutting down.<br>
After the <a href=KBEngine.html#onBaseAppShutDown>onBaseAppShutDown(state=0)</a> 
is called, this function returns True.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
True if the server is shutting down, otherwise False.
</td></tr>
</table>
</p>


<a name="listPathRes"></a><p class="function_definition">
<span class="function_definition">def listPathRes( <i>path, extension</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get a list of resources in a resource directory<br>
Note: Resources must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Example:
<br>
<br>
>>>KBEngine.listPathRes("scripts/cell/interfaces")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", "txt")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", "txt|py")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", ("txt", "py"))
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource directory
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>extension</i></span></td><td><span class="function_parameter_description">
string, optional parameter, file extension to filter by
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Tuple, resource list.
</td></tr>
</table>
</p>



<a name="lookUpEntityByDBID"></a><p class="function_definition">
<span class="function_definition">def lookUpEntityByDBID( <i>entityType, dbID, callback, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Queries whether an entity is checked out of the database, and if the 
entity has been checked out of the database, <a href="KBEngine.html">KBEngine</a>
will return the <a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a> 
in the callback.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of Entity to query. Valid entity types are 
listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
Specifies the database ID of the <a href="../Classes/Entity.html">Entity</a> 
to be queried. The database ID is stored in the entity's <href=../Classes/Entity.html#databaseID>databaseID</a> 
attribute.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
A callback with one parameter, True when the entity is not checked out 
from the database, if it is checked out then it is the <a href="../Classes/Entity.html">Entity</a>'s <a href=../../keywords.html#EntityCall>entityCall</a>. 
False in any other case.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specifies a database interface. Uses the 
"default" interface by default. Database interfaces are defined in kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>



<a name="matchPath"></a><p class="function_definition">
<span class="function_definition">def matchPath( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the absolute path of a resource from its relative path.<br>
Note: Resources must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Examples:
<br>
<br>
>>>KBEngine.matchPath("scripts/entities.xml")<br>
'/home/kbe/kbengine/demo/res/scripts/<a href=../../keywords.html#entities.xml>entities.xml</a>'
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource (including its name).
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, the absolute path of the resource.
</td></tr>
</table>
</p>




<a name="open"></a><p class="function_definition">
<span class="function_definition">def open( <i>res, mode, encoding</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Use this function to open resources with their relative paths.<br>
Note: Resource must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>mode</i></span></td><td><span class="function_parameter_description">
string, optional parameter, the default is 'r', file operation mode:<br>
r Open in only read mode,<br>
w Open in write mode,<br>
a Open in append mode (Start from EOF, create new file if necessary) <br>
r+ Open <br>
w+ in read/write mode Open in read/write mode (see w) <br>
a+ Open in read/write mode (See a) <br>
rb Opens <br>
wb in binary read mode Opens in binary write mode (see w) <br>
ab Opens in binary append mode (see a) <br>
rb+ Opens in binary read and write mode (see r+) <br>
wb+ Opens in binary read and write mode (see w+ ) <br>
ab+ opens in binary read/write mode (see a+) <br>
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>encoding</i></span></td><td><span class="function_parameter_description">
string, optional parameter, the name of the encoding used to decode or encode the file, the default encoding is platform dependent.
</span></td></tr>

</table>
</p>

<a name="publish"></a><p class="function_definition">
<span class="function_definition">def publish( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function returns the server's current release mode.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
int8, 0: debug, 1: release, others can be customized.
</td></tr>
</table>
</p>

<a name="quantumPassedPercent"></a><p class="function_definition">
<span class="function_definition">def quantumPassedPercent( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns the percentage of the current tick that takes one clock cycle.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Returns the percentage of the current tick that takes one clock cycle.
</td></tr>
</table>
</p>



<a name="registerReadFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def registerReadFileDescriptor( <i>fileDescriptor, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a callback function that is called when the file descriptor is 
readable.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
socket descriptor/file descriptor.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
A callback function with the socket descriptor/file descriptor as its only 
parameter.
</span></td></tr>

</table>
</p>

<a name="registerWriteFileDescriptor"></a><p class="function_definition">
<span class="function_definition">
def registerWriteFileDescriptor( <i>fileDescriptor, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a callback function that is called when the socket descriptor/file 
descriptor is writable.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
socket descriptor/file descriptor
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
A callback function with the socket descriptor/file descriptor as its only parameter.
</span></td></tr>

</table>
</p>



<a name="reloadScript"></a><p class="function_definition">
<span class="function_definition">def reloadScript( <i>fullReload</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Reloads Python modules related to entity and custom data types. The 
current entity's class is set to the newly loaded class. This method 
should only be used for development mode and not for product mode. The 
following points should be noted:
<br><br>
1) The overloaded script can only be executed on <a href="../index.html">Baseapp</a>, 
and the user should ensure that all server components are loaded.
<br><br>
2) The custom type should ensure that the objects already instantiated in 
memory are updated after the script is reloaded. Here is an example:
<br><br>

<pre>for e in <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#entities>entities</a>.values():
   if type( e ) is Avatar.Avatar:
      e.customData.__class__ = CustomClass
</pre>
When this mehod completes, <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onInit>onInit</a>( True ) 
is called.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fullReload</i></span></td><td><span class="function_parameter_description">
bool, optional parameter that specifies whether to reload entity definitions 
at the same time. If this parameter is False, the entity definition will 
not be reloaded. The default is True.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>True if the reload succeeds, otherwise False.
</td></tr>
</table>
</p>




<a name="scriptLogType"></a><p class="function_definition">
<span class="function_definition">def scriptLogType( <i>logType</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Set the type of information output by the current Python.print (Reference: KBEngine.LOG_TYPE_*).
</div>



<a name="setAppFlags"></a><p class="function_definition">
<span class="function_definition">def setAppFlags( <i>flags</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Set the flags of the current engine APP.
<br>
<br>
KBEngine.APP_FLAGS_NONE // Default (not set)<br>
KBEngine.APP_FLAGS_NOT_PARTCIPATING_LOAD_BALANCING //Do not participate in load balancing<br>
<br>
Example:<br>
KBEngine.setAppFlags(KBEngine.APP_FLAGS_NOT_PARTCIPATING_LOAD_BALANCING | KBEngine.APP_FLAGS_*)
</div>


<a name="time"></a><p class="function_definition">
<span class="function_definition">def time( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This method returns the current game time (number of cycles).
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
uint32, the time of the current game. This refers to the number of cycles. 
The period is affected by the frequency. The frequency is determined by 
the configuration file <a href=../../keywords.html#kbengine.xml>kbengine.xml</a> or <a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->gameUpdateHertz.
</td></tr>
</table>
</p>


<a name="urlopen"></a><p class="function_definition">
<span class="function_definition">def urlopen( <i>url, callback, postData, headers</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function is providing an external HTTP/HTTPS asynchronous request.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>url</i></span></td><td><span class="function_parameter_description">
A valid HTTP/HTTPS URL.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter with a callback object (for example, a function) that requests execution results. This callback takes five parameters: the HTTP request return code (eg: 200), 
the returned content, the returned HTTP protocol header, whether it succeeded, and the requested URL.
<br>
Example:<br>
def 
onHttpCallback(httpcode, data, headers, success, url):<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(httpcode, data, headers, success, url)  <br>
<br>
As the above example shows:
<br><p class="function_parameter_description"></p>httpcode:The parameter corresponds to the &quot;HTTP request return code&quot;, is an integer.
<p class="function_parameter_description"></p>data:The parameter is &ldquo; returned content & rdquo;, it is a string.
</p>
<p class="function_parameter_description">headers:The parameter is the HTTP protocol header returned by the server, such as:{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
<p class="function_parameter_description">success:Whether the execution is successful or not, when the request execution has an error, it is False, and the error information can be further judged by httpcode.
</p>
<p class="function_parameter_description"></p>url:Is the URL used by the request.
</p>
</td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>postData</i></span></td><td><span class="function_parameter_description">
Optional parameter, the default is GET mode request server. If you need POST mode, please provide the content that needs POST. The engine will automatically request the server using POST, is an bytes.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>headers</i></span></td><td><span class="function_parameter_description">
Optional parameter, HTTP header used when requesting, such as：{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
</span></td></tr>

</table>
</p>

	


<hr>
<h2>Callback functions documentation</h2>

<a name="onBaseAppReady"></a><p class="function_definition">
<span class="function_definition">def onBaseAppReady( <i>isBootstrap</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This callback function is called when the current <a href="../index.html">Baseapp</a> 
process is ready.<br>
Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isBootstrap</i></span></td><td><span class="function_parameter_description">
bool, True if this is the first <a href="../index.html">Baseapp</a> started
</span></td></tr>

</table>
</p>

<a name="onBaseAppShutDown"></a><p class="function_definition">
<span class="function_definition">def onBaseAppShutDown( <i>state</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The <a href="../index.html">Baseapp</a> shutdown procedure will call 
this function. <br>
Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>state</i></span></td><td><span class="function_parameter_description">
If state is 0, it means that it is before all clients are disconnected, 
if state is 1, it means that it is before all entities are written to the database, 
if state is 2, it mean all entities have been written to the database.
</span></td></tr>

</table>
</p>

<a name="onCellAppDeath"></a><p class="function_definition">
<span class="function_definition">def onCellAppDeath( <i>addr</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This callback function will be called on the death of a cellapp.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>addr</i></span></td><td><span class="function_parameter_description">
Dead cellapp address.<br>
tuple:(ip, port) Network byte order
</span></td></tr>

</table>
</p>

<a name="onFini"></a><p class="function_definition">
<span class="function_definition">def onFini( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This callback function is called  after the engine is officially shut down. 
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<a name="onBaseAppData"></a><p class="function_definition">
<span class="function_definition">def onBaseAppData( <i>key, value</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.baseAppData changes.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
The key of the changed data.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
The value of the changed data.
</span></td></tr>

</table>
</p>

<a name="onBaseAppDataDel"></a><p class="function_definition">
<span class="function_definition">def onBaseAppDataDel( <i>key</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.baseAppData is deleted.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
Deleted data key
</span></td></tr>

</table>
</p>

<a name="onGlobalData"></a><p class="function_definition">
<span class="function_definition">def onGlobalData( <i>key, value</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.globalData changes.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
The key of the changed data
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
The value of the changed data
</span></td></tr>

</table>
</p>

<a name="onGlobalDataDel"></a><p class="function_definition">
<span class="function_definition">def onGlobalDataDel( <i>key</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.globalData is deleted.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
Deleted data key.
</span></td></tr>

</table>
</p>

<a name="onInit"></a><p class="function_definition">
<span class="function_definition">def onInit( <i>isReload</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back after all scripts have been initialized after 
the engine started.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isReload</i></span></td><td><span class="function_parameter_description">
bool, whether it was triggered after rewriting the loading script.
</span></td></tr>

</table>
</p>

<a name="onLoseChargeCB"></a><p class="function_definition">
<span class="function_definition">def onLoseChargeCB( <i>orderID, dbID, success, datas</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when <a href=../../interfaces/Modules/KBEngine.html>KBEngine</a>.<a href=../../interfaces/Modules/KBEngine.html#chargeResponse>chargeResponse</a> is called in 
and the order is lost or unknown.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>ordersID</i></span></td><td><span class="function_parameter_description">
string, order ID.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
uint64, the database ID of the entity, see: <a href=../Classes/Entity.html#databaseID>Entity.databaseID</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>success</i></span></td><td><span class="function_parameter_description">
bool, is it successful?
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, with information
</span></td></tr>
</table>
</p>

<a name="onReadyForLogin"></a><p class="function_definition">
<span class="function_definition">def onReadyForLogin( <i>isBootstrap</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
When the engine is started and initialized, it will always call this function 
to ask whether the script layer is ready. If the script layer is ready, 
loginapp allows the client to log in.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isBootstrap</i></span></td><td><span class="function_parameter_description">
bool, True if this is the first <a href="../index.html">Baseapp</a> started.
</span></td></tr>



</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>If the return value is greater than or equal to 1.0, the script 
layer is ready; otherwise, return a value from 0 to less than 1.0.
</td></tr>
</table>
</p>



<a name="onReadyForShutDown"></a><p class="function_definition">
<span class="function_definition">def onReadyForShutDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
If this callback function is implemented in the script, it is called when 
the process is ready to exit.<br><br>

You can use this callback to control when the process exits.<br>
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
bool if it returns True, it allows the process to exit. Returning other 
values will cause the process to ask again after a period of time.
</td></tr>
</table>
</p>



<a name="onAutoLoadEntityCreate"></a><p class="function_definition">
<span class="function_definition">def onAutoLoadEntityCreate( <i>entityType, dbID</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Called when an automatically loaded entity is created. If the script layer 
implements this callback, the entity is created by the script layer, 
otherwise the engine defaults to create the entity using 
createEntityAnywhereFromDBID.<br><br>

This callback is envoked because <a href=../Classes/Entity.html#writeToDB>Entity.writeToDB</a> 
was set to automatically load the entity.
<br>Note: this callback takes precedence over onBaseAppReady execution 
and can be checked for onBaseAppReady when the entity is loaded.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, specifies the type of entity to query. Valid entity types are listed in <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbID</i></span></td><td><span class="function_parameter_description">
specifies the database ID of the <a href="../Classes/Entity.html">Entity</a> 
to be queried. The database ID of this entity is stored in the entity's <a href=../Classes/Entity.html#databaseID>databaseID</a> attribute.
</span></td></tr>




</table>
</p>



<hr>
<h2>Attributes documentation</h2>

<a name="LOG_ON_ACCEPT"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_ON_ACCEPT</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This constant is returned by <a href="../Classes/Proxy.html">Proxy</a>.<a href=../Classes/Proxy.html#onLogOnAttempt>onLogOnAttempt</a>, 
and means that the new client is allowed to bind to a <a href="../Classes/Proxy.html">Proxy entity</a>.<br>
If the <a href="../Classes/Proxy.html">Proxy entity</a> already has a 
client binding, the previous client will be kicked out.
</div>

<a name="LOG_ON_REJECT"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_ON_REJECT</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This constant is returned by <a href="../Classes/Proxy.html">Proxy</a>.<a href=../Classes/Proxy.html#onLogOnAttempt>onLogOnAttempt</a>, 
which means that the current client is bound to the <a href="../Classes/Proxy.html">Proxy entity.</a>
</div>

<a name="LOG_ON_WAIT_FOR_DESTROY"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_ON_WAIT_FOR_DESTROY</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This constant is returned by <a href="../Classes/Proxy.html">Proxy</a>.<a href=../Classes/Proxy.html#onLogOnAttempt>onLogOnAttempt</a>. 
The current requesting client will wait until the <a href="../Classes/Proxy.html">Proxy entity</a> 
is completely destroyed and the underlying layer will complete the 
subsequent binding process. Before this returns, <a href="../Classes/Proxy.html">Proxy</a>.<a href=../Classes/Entity.html#destroy>destroy</a> or <a href="../Classes/Proxy.html">Proxy</a>.<a href=../Classes/Entity.html#destroyCellEntity>destroyCellEntity</a>
should be invoked.
</div>

<a name="LOG_TYPE_DBG"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_DBG</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is debug.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_ERR"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_ERR</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is error.<br>
Set by<a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_INFO"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_INFO</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is general information.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_NORMAL"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_NORMAL</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is normal.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_WAR"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_WAR</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is warning.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="NEXT_ONLY"></a><p class="attribute_definition">
<span class="attribute_definition">NEXT_ONLY</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This constant is used for the <a href="../Classes/Entity.html#shouldAutoBackup">Entity.shouldAutoBackup</a> and <a href="../Classes/Entity.html#shouldAutoArchive">Entity.shouldAutoArchive</a> 
attributes and means that the entity is backed up automatically next time 
it is deemed acceptable, and then the attribute is automatically set to false (0).
</div>

<a name="component"></a><p class="attribute_definition">
<span class="attribute_definition">component</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This is the component that is running in the current Python environment. 
(So far) Possible values are 'cellapp', 'baseapp', 'client', 'dbmgr', 'bots', and 'editor'.
</div>

<a name="entities"></a><p class="attribute_definition">
<span class="attribute_definition">entities</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
entities is a dictionary object that contains all the entities in the 
current process.
<br>
Debugging leaked entities (instances that call destroy without releasing 
memory, usually due to being referenced):<br>
<pre>
>>> KBEngine.entities.garbages.items()
[(1025, Avatar object at 0x7f92431ceae8.)]
<br>
>>> e = _[0][1]
>>> import gc
>>> gc.get_referents(e)
[{'spacesIsOk': True, 'bootstrapIdx': 1}, <class 'Avatar.Avatar'>]
</pre>
<br>
Debugging a leaked KBEngine-encapsulated Python object:<br>
<a href=#debugTracing>KBEngine.debugTracing</a>
</div>

<p>
<span class="attribute_type">Types:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td><a href="Entities.html">Entities</a>
</td></tr>
</table>
</p>

<a name="baseAppData"></a><p class="attribute_definition">
<span class="attribute_definition">baseAppData</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This attribute contains a dictionary-like object that is automatically 
synchronized across all BaseApps. When a value in the dictionary is 
modified, the change is broadcast to all BaseApps.

<br><br>
Example:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#baseAppData>baseAppData</a>[ "hello" ] = "there"
</pre>
<br><br>
The rest of the BaseApps can access the following:

<pre>print <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#baseAppData>baseAppData</a>[ "hello" ]
</pre>
<br><br>
Keys and values can be of any type, but these types must be encapsulated 
and unpacked on all target components.
<br><br>
When a value is changed or deleted, a callback function is called on all 
components. 
See: <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onBaseAppData>onBaseAppData</a> and <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onDelBaseAppData>onDelBaseAppData</a>.
<br><br>
Note: Only top-level value changes will be broadcast. If you have a value 
(such as a list) that changes an internal value (such as just changing a 
number), this information will not be broadcast.
<br><br>
Do not do the following:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#baseAppData>baseAppData</a>[ "list" ] = [1, 2, 3]
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#baseAppData>baseAppData</a>[ "list" ][1] = 7
</pre>
The local access is [1, 7, 3] and the remote access is [1, 2, 3].
</div>

<a name="globalData"></a><p class="attribute_definition">
<span class="attribute_definition">globalData</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This attribute contains a dictionary-like object that is automatically 
synchronized across all BaseApps and CellApps. When a value in the dictionary is 
modified, the change is broadcast to all BaseApps and CellApps.
<br><br>
example:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "hello" ] = "there"
</pre>
<br><br>
The other <a href="../index.html">Baseapps</a> and <a href="../../cellapp/index.html">Cellapps</a> can access the following:

<pre>print <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "hello" ]
</pre>
<br><br>
Keys and values can be of any type, but these types must be encapsulated 
and unpacked on all target components.
<br><br>
When a value is changed or deleted, a callback function is called on all 
components. 
See: <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onGlobalData>onGlobalData</a> and <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onGlobalDataDel>onGlobalDataDel</a>.
<br><br>
Note: Only top-level value changes will be broadcast. If you have a value 
(such as a list) that changes an internal value (such as just changing a 
number), this information will not be broadcast.
<br><br>
Do not do the following:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "list" ] = [1, 2, 3]
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "list" ][1] = 7
</pre>
The local access is [1, 7, 3] and the remote access is [1, 2, 3].
</div>

<hr>
<p class="copyrightFooter">Copyright KBEngine</p>
</body>
</html>
